//
//  TestProblem324.swift
//  LeetCodeTests
//
//  Created by 武侠 on 2023/6/28.
//  Copyright © 2023 zhulongiMac02. All rights reserved.
//

import XCTest
@testable import LeetCode

final class TestProblem324: XCTestCase {

    var problem = Problem324()
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    // MARK: - 排序
    func testProblem324_Case1() throws {
        var nums = [1,5,1,1,6,4]
        problem.wiggleSort(&nums)
        var isSort = true
        var i = 1
        while i < nums.count {
            if nums[i] <= nums[i-1] {
                isSort = false
                break
            } else if i + 1 < nums.count, nums[i] <= nums[i+1] {
                isSort = false
                break
            }
            i += 2
        }
        
        XCTAssertTrue(isSort)
    }
    
    func testProblem324_Case2() throws {
        var nums = [1,3,2,2,3,1]
        problem.wiggleSort(&nums)
        var isSort = true
        var i = 1
        while i < nums.count {
            if nums[i] <= nums[i-1] {
                isSort = false
                break
            } else if i + 1 < nums.count, nums[i] <= nums[i+1] {
                isSort = false
                break
            }
            i += 2
        }
        
        XCTAssertTrue(isSort)
    }
    
    func testProblem324_Case3() throws {
        var nums = [4,5,5,6]
        problem.wiggleSort(&nums)
        var isSort = true
        var i = 1
        while i < nums.count {
            if nums[i] <= nums[i-1] {
                isSort = false
                break
            } else if i + 1 < nums.count, nums[i] <= nums[i+1] {
                isSort = false
                break
            }
            i += 2
        }
        
        XCTAssertTrue(isSort)
        
    }
}
